//
//  CViewController.m
//  nstimer循环引用
//
//  Created by keisun on 2018/11/1.
//  Copyright © 2018年 keisun. All rights reserved.
//

#import "CViewController.h"
#import "WeakProxy.h"
#import "YYWeakProxy.h"

@interface CViewController ()
@property (nonatomic, strong) CADisplayLink *link;
@property (nonatomic, assign) int64_t num;
@end

@implementation CViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2 target:[YYWeakProxy proxyWithTarget:self]  selector:@selector(timerAction) userInfo:nil repeats:YES];
//    self.timer = timer;
    
    _link = [CADisplayLink displayLinkWithTarget:[WeakProxy proxyWithTarget:self] selector:@selector(printNum)];
    _link.preferredFramesPerSecond = 1;
    [_link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 60, 40)];
    [btn setTitle:@"c返回" forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor redColor];
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn];
}

-(void)printNum{
    NSLog(@"%lld", _num++);
}

-(void)btnClick{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)dealloc{
    [_link invalidate];
    NSLog(@"CViewController销毁了");
}
@end
